package com.carp.springframework.context.support;

import com.carp.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import com.carp.springframework.beans.factory.support.CGLibInstantiationStrategy;
import com.carp.springframework.beans.factory.support.DefaultListableBeanFactory;

/**
 * @author lile
 * @date 2023/2/17
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    @Override
    protected void refreshBeanFactory() {
        beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
    }

    private DefaultListableBeanFactory createBeanFactory() {
        return new DefaultListableBeanFactory(new CGLibInstantiationStrategy());
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory);

    @Override
    protected ConfigurableListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
